package demo;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:34398
 * Date:2024-07-25
 * Time:10:46
 */



class SingleL{
    private static Object lock=new Object();
    private static volatile SingleL instance=null;//先置为空，要的时候才实例化,最后volatile禁止指令重排序
    public static SingleL getInstance(){

        if(instance==null){
            /*在同步块中执行*/
            synchronized(lock){
                if(instance==null){
                    instance=new SingleL();
                }
            }
        }
        return instance;
    }
}


public class Test {
}
